home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / ShowHelp / Show_help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-08  |  34.8 KB  |  1,232 lines  |  [TEXT/KAHL]

  1. #define USE_PICTS    1    /* 1 if PICTs are to be displayed, 0 for text only */
  2. #define ONE_RESOURCE 1    /* 1 for Get1Resource, 0 for GetResource, etc. */
  3. #define COMPRESSION    1    /* compressed TEXT/styl or PICTs */
  4. #define STANDALONE    1
  5.  
  6. #define CHECKPOINTS 0
  7. #define ASSERTIONS    0
  8.  
  9. #define    PREFLIGHT_MEMORY    20000L
  10.  
  11. #if ASSERTIONS
  12.     #define    ASSERT_SET_NIL(lvalue)    lvalue = NIL
  13. #else
  14.     #define    ASSERT_SET_NIL(lvalue)
  15. #endif
  16.  
  17. #if STANDALONE
  18.     #define        Show_help    main
  19. #else
  20.     void    main( void );
  21. #endif
  22.  
  23. #include "Show_help.h"
  24. #include "Show_help typedefs.h"
  25.  
  26. /*
  27.     Show_help by James W. Walker, June 1991
  28.     
  29.     version 2.0, updated July 1992
  30.     
  31.     This code is freely usable.  If you want to show your gratitude,
  32.     you could send me a free copy of whatever program you develop
  33.     with it.
  34.     
  35.     e-mail:
  36.         Internet            76367.2271@compuserve.com
  37.         CIS                    76367,2271
  38.         America Online        JWWalker
  39.     
  40.     This code displays scrolling text in a dialog box.  The text comes
  41.     from TEXT/styl resources, which can be created with ResEdit 2.1 or
  42.     with an accompanying HyperCard stack.
  43.     The text cannot be edited, but one can select text and copy it to
  44.     the clipboard using command-C, or save it as a TeachText file.
  45.     
  46.     Pictures can be included in the text using the same scheme as
  47.     TeachText: Each option-space character indicates where the top
  48.     edge of a picture should go, and pictures are centered horizontally.
  49.     Pictures come from consecutively-numbered PICT resources.  
  50.     
  51.     A popup menu can be used to jump to "bookmarks", which are indicated
  52.     by tab characters at ends of lines.
  53.     
  54.     Prototype:
  55.     
  56.     pascal void Show_help( short help_info_id,
  57.                 pascal void (*Handle_update)( WindowPtr ) );
  58.         
  59.     TO DO: error recovery, support for modeless use.
  60. */
  61.  
  62.  
  63.  
  64. #ifndef NIL
  65.     #define        NIL        0L
  66. #endif
  67.  
  68. #if ONE_RESOURCE
  69.     #define GetResource            Get1Resource
  70.     #define CountResources        Count1Resources
  71.     #define GetNamedResource    Get1NamedResource
  72. #endif ONE_RESOURCE
  73.  
  74. #if ASSERTIONS
  75.     #define        ASSERT(x,y)        if (!(x)) {DebugStr("\p" y);}
  76. #else
  77.     #define        ASSERT(x,y)
  78. #endif ASSERTIONS
  79.  
  80. #if CHECKPOINTS
  81.     #define CKPT(x)        DebugStr( "\p" x )
  82. #else
  83.     #define CKPT(x)
  84. #endif CHECKPOINTS
  85.  
  86. enum {
  87.     c_OK = 1,    /* OK button */
  88.     c_help,        /* userItem for our help display */
  89.     c_save,        /* Button to save as TeachText */
  90.     c_menu        /* userItem for popup menu */
  91. };
  92.  
  93. #define        SCROLLBAR_WIDTH    16
  94. #define        TEXT_INSET        4
  95.  
  96. #define        INITIAL_HIGHLIGHTS        8
  97.  
  98.  
  99.  
  100. /* Prototypes of private routines
  101. */
  102. static pascal Boolean Help_filter( DialogPtr dialog,
  103.     EventRecord    *event, short *itemHit);
  104. static pascal void  Text_userItem_proc( WindowPtr the_window, short item_num );
  105. static pascal void  Menu_userItem_proc( WindowPtr the_window, short item_num );
  106. static pascal void Scroll_text( ControlHandle the_bar, short part_code );
  107. static pascal Auto_scroll( void );
  108. static void Handle_scroll( DialogPtr dialog,
  109.     short the_part, Point local_point );
  110. static void Adjust_text( DialogPtr dialog );
  111. static void Save_text( TEHandle the_text, StringPtr default_filename );
  112. static void Topic_menu( DialogPtr dlog, MenuHandle help_popup );
  113. static MenuHandle Build_popup( TEHandle    the_text, StringPtr default_menuname );
  114. static short    Find_char(
  115.             Handle    data_h,        // handle to a block of characters
  116.             short    offset,        // initial offset within block
  117.             char    what );        // the character we're looking for
  118.  
  119. #if COMPRESSION
  120.     static Handle Get_compressed_resource( ResType    the_type, short the_ID );
  121.     static void Release_compressed_resource( Handle rsrc_h );
  122.     static void Dispose_compressed_data( Handle the_handle );
  123. #else
  124.     #define Get_compressed_resource            GetResource
  125.     #define Release_compressed_resource        ReleaseResource
  126.     #define    Dispose_compressed_data(x)
  127. #endif
  128.  
  129. #if USE_PICTS
  130. static void Find_pictures( DialogPtr dlog, short first_pict_id );
  131. static void Draw_picts( WindowPtr the_window, Rect *update_rect );
  132. static pascal void High_hook( Rect *high_rect );
  133. static void Do_deferred_hilites( help_ptr  hptr, Rect *update_rect );
  134. static void Push_highlight( high_info **hh, Rect *rect );
  135. static Boolean Pop_highlight( high_info **hh, Rect *rect );
  136. #endif
  137.  
  138. /* ------------------------- Show_help --------------------------------- */
  139. pascal void Show_help( short info_id,
  140.                 pascal void (*Handle_update)( WindowPtr what_window ) )
  141. {
  142.     register    DialogPtr    dptr;
  143.     register    TEHandle    the_text;
  144.     short        itype, ihit;
  145.     Handle        item_h;
  146.     Rect        help_item_box, box;
  147.     Handle            help_TEXT;
  148.     StScrpHandle    help_styl;
  149.     GrafPtr        save_port;
  150.     Rect        dest, view;
  151.     ControlHandle    the_bar;
  152.     short        max_scroll, nLines;
  153.     Point        place;
  154.     MenuHandle    help_popup;
  155.     CursHandle    watch_cursor;
  156.     Show_help_info    **the_info;
  157.     StringPtr    default_menuname, default_filename;
  158.     short        which_pict;
  159.     Handle        save_mbar;
  160.     MenuHandle    fake_apple;
  161.     
  162.     /*
  163.         I'm too lazy to check for a memory error in every possible
  164.         place, so I'll just make sure there is a reasonable amount
  165.         available before starting.
  166.     */
  167.     item_h = NewHandle( PREFLIGHT_MEMORY );
  168.     if (item_h == NIL)
  169.     {
  170.         SysBeep(1);
  171.         return;
  172.     }
  173.     else
  174.         DisposHandle( item_h );
  175.  
  176.     the_info = (Show_help_info **) GetResource( 'Hlp?', info_id );
  177.     ASSERT( the_info != NIL, "Hlp? resource missing" );
  178.     HLock( (Handle) the_info );
  179.     default_filename = (**the_info).strings;
  180.     default_menuname = default_filename + default_filename[0] + 1;
  181.  
  182.     /*
  183.         Get the dialog, which has extra info tacked on the end.
  184.     */
  185.     dptr = (DialogPtr) NewPtr( sizeof(help_record) );
  186.     ASSERT( dptr != NIL, "NewPtr failed for help_record" );
  187.     dptr = GetNewDialog( (**the_info).DLOG_ID, (DialogPeek) dptr, (WindowPtr)-1L );
  188.     ASSERT( dptr != NIL, "Failed GetNewDialog" );
  189.     GetPort( &save_port );
  190.     SetPort( dptr );
  191.  
  192.     ((help_ptr) dptr)->Handle_update = Handle_update;
  193.     
  194.     watch_cursor = GetCursor( watchCursor );
  195.     HLock( (Handle) watch_cursor );
  196.     SetCursor( *watch_cursor );
  197.     ((help_ptr) dptr)->ibeam_cursor = GetCursor( iBeamCursor );
  198.     HLock( (Handle) ((help_ptr) dptr)->ibeam_cursor );
  199.     
  200. #if USE_PICTS
  201.     ((help_ptr) dptr)->high = (high_info **) NewHandle(
  202.                 sizeof(high_info) + INITIAL_HIGHLIGHTS * sizeof(Rect) );
  203.     ASSERT( ((help_ptr) dptr)->high != NIL, "Failed to get highlight record");
  204.     (**((help_ptr) dptr)->high).array_size = INITIAL_HIGHLIGHTS;
  205.     (**((help_ptr) dptr)->high).high_waiting = 0;
  206. #endif
  207.  
  208.     help_TEXT = Get_compressed_resource( 'TEXT', (**the_info).TEXT_ID );
  209.     if (help_TEXT == NIL)
  210.     {
  211.         ASSERT(false, "Failed to find help TEXT resource" );
  212.         goto getout;
  213.     }
  214.     help_styl = (StScrpHandle)
  215.         Get_compressed_resource( 'styl', (**the_info).styl_ID );
  216.     if (help_styl == NIL)
  217.     {
  218.         DisposHandle( help_TEXT );
  219.         ASSERT_SET_NIL( help_TEXT );
  220.         ASSERT( false, "Failed to find styl resource" );
  221.         goto getout;
  222.     }
  223.     HLock( help_TEXT );
  224.     
  225.     GetDItem( dptr, c_help, &itype, &item_h, &help_item_box );
  226.     SetDItem( dptr, c_help, itype, (Handle) Text_userItem_proc, &help_item_box );
  227.     view = help_item_box;
  228.     InsetRect( &view, 1, 1 );
  229.     view.right -= SCROLLBAR_WIDTH;
  230.     dest = view;
  231.     InsetRect( &dest, TEXT_INSET, 0 );
  232.     the_text = TEStylNew( &dest, &view );
  233.     ASSERT( the_text != NIL, "Failed TEStylNew." );
  234.     
  235.     TEStylInsert( *help_TEXT, GetHandleSize(help_TEXT),
  236.         help_styl, the_text );
  237.     TEActivate( the_text );
  238.     Release_compressed_resource( (Handle) help_styl );
  239.     ASSERT_SET_NIL( help_styl );
  240.     Release_compressed_resource( help_TEXT );
  241.     ASSERT_SET_NIL( help_TEXT );
  242.     nLines = (**the_text).nLines;
  243.     SetWRefCon( dptr, (long)the_text );
  244.     max_scroll = TEGetHeight( (long) nLines, 1L, the_text )
  245.         - (view.bottom - view.top);
  246.     
  247.     help_item_box.left = help_item_box.right - SCROLLBAR_WIDTH;
  248.     the_bar = NewControl( dptr, &help_item_box, "\p", true,
  249.         0, 0, max_scroll, scrollBarProc, NIL );
  250.     ASSERT( the_bar != NIL, "Failed NewControl for scroll bar." );
  251.     ((help_ptr) dptr)->scrollbar = the_bar;
  252.  
  253. #if USE_PICTS
  254.     Find_pictures( dptr, (**the_info).first_PICT_ID );
  255. #endif
  256.     help_popup = Build_popup( the_text, default_menuname );
  257.  
  258.     TEAutoView( TRUE, the_text );    /* Permit auto-scrolling */
  259.     CKPT( "Installing ClikLoop" );
  260.     (**the_text).clikLoop = (ProcPtr)Auto_scroll;
  261. #if USE_PICTS
  262.     (**the_text).highHook = (ProcPtr) High_hook;
  263.     ((help_ptr)dptr)->high_defer_flag = false;
  264. #endif
  265.  
  266.     GetDItem( dptr, c_menu, &itype, &item_h, &box );
  267.     SetDItem( dptr, c_menu, itype, (Handle) Menu_userItem_proc, &box );
  268.     
  269.     ((help_ptr)dptr)->save_clip = NewRgn();    /* Used in Draw_picts */
  270.     ASSERT( ((help_ptr)dptr)->save_clip != NIL,
  271.         "NewRgn failed for save_clip" );
  272.     
  273.     /*
  274.         My Fake_ModalDialog does not disable the menu bar the way
  275.         the real one does.  I want to disable everything except the
  276.         system menus: help, keyboard, application.  After clearing
  277.         the menu bar, I have to add one menu, or else I wouldn't get the
  278.         system menus.
  279.     */
  280.     save_mbar = GetMenuBar();
  281.     ClearMenuBar();
  282.     fake_apple = NewMenu(1,"\p\024");
  283.     InsertMenu( fake_apple, 0 );
  284.     DisableItem( fake_apple, 0 );
  285.     DrawMenuBar();
  286.  
  287.     ShowWindow( dptr );
  288.     InitCursor();
  289.  
  290.     do {
  291.         Fake_ModalDialog( (ProcPtr) Help_filter, &ihit );
  292.         if (ihit == c_save)
  293.             Save_text( the_text, default_filename );
  294.         else if (ihit == c_menu)
  295.             Topic_menu( dptr, help_popup );
  296.     } while (ihit != c_OK);
  297.     
  298.     SetMenuBar( save_mbar );
  299.     DisposeMenu( fake_apple );
  300.     DrawMenuBar();
  301.     DisposHandle( save_mbar );
  302.  
  303.     DisposeRgn( ((help_ptr)dptr)->save_clip );
  304.     ASSERT_SET_NIL( ((help_ptr)dptr)->save_clip );
  305.     ReleaseResource( (Handle) the_info );
  306.     
  307. #if USE_PICTS
  308. #if COMPRESSION
  309.     for (which_pict = 0; which_pict < ((help_ptr)dptr)->pict_count; ++which_pict)
  310.     {
  311.         Dispose_compressed_data( (Handle)
  312.             ((help_ptr)dptr)->pict_data[which_pict].pict );
  313.     }
  314. #endif /* COMPRESSION */
  315.     DisposPtr( (Ptr) ((help_ptr)dptr)->pict_data );
  316.     ASSERT_SET_NIL( ((help_ptr)dptr)->pict_data );
  317.     DisposHandle( (Handle) ((help_ptr) dptr)->high );
  318.     ASSERT_SET_NIL( ((help_ptr) dptr)->high );
  319. #endif /* USE_PICTS */
  320.  
  321.     TEDispose( the_text );
  322.     ASSERT_SET_NIL( the_text );
  323. getout:
  324.     DisposDialog( dptr );
  325.     DisposeMenu( help_popup );
  326.     SetPort( save_port );
  327. }
  328.  
  329. #if USE_PICTS
  330. /*    ----------------------------------------------------------------
  331.     High_hook            The highHook routine documented in IM IV
  332.                         (I think) expects the address of a Rect on
  333.                         top of the stack, and the return address
  334.     next on the stack.  This is opposite from the Pascal or C calling
  335.     protocol, so we have to use assembly language to swap those items.
  336.  
  337.     This deferred highlighting scheme is used to ensure that highlighting
  338.     will be done after any pictures have been drawn, not before.  To do
  339.     otherwise can cause pictures to be incorrectly highlighted during
  340.     auto-scrolling.  This error can be seen in TeachText.
  341.     ----------------------------------------------------------------
  342. */
  343. static pascal void High_hook( Rect *the_rect )
  344. {
  345.     register help_ptr    front;
  346.     
  347.     asm {
  348.         moveM.L        4(A6), A0/A1    ; load Rect address, return address
  349.         EXG.L        A0, A1            ; swap
  350.         moveM.L        A0/A1, 4(A6)    ; store return address, Rect address
  351.     }
  352.     CKPT( "High_hook");
  353.     front = (help_ptr) FrontWindow();
  354.     if ( (front != NIL) &&
  355.         (GetPtrSize((Ptr)front) == sizeof(help_record)) &&
  356.         !EmptyRect( the_rect ) )
  357.     {
  358.         if (!front->high_defer_flag)
  359.         {
  360.             HiliteMode &= ~(1 << hiliteBit);
  361.             InvertRect( the_rect );
  362.         }
  363.         else
  364.         {
  365.             Push_highlight( front->high, the_rect );
  366.         }
  367.     }
  368. }
  369.  
  370. /*    ---------------------------------------------------------------------
  371.     Push_highlight            Push a deferred highlight on the stack.
  372.                             Previously, the stack was a fixed size, because
  373.                             there never seemed to be more than 3 deferred
  374.     highlights at a time.  But then it turned out that under the Japanese
  375.     system software, there could be 7 highlights, even with the same
  376.     English text.  So now the stack can grow.
  377.     ---------------------------------------------------------------------
  378. */
  379. static void Push_highlight( high_info **hh, Rect *rect )
  380. {
  381.     if ( (**hh).high_waiting >= (**hh).array_size )
  382.     {
  383.         SetHandleSize( (Handle)hh, sizeof(high_info) +
  384.             (INITIAL_HIGHLIGHTS + (**hh).array_size) * sizeof(Rect) );
  385.         ASSERT( MemError() == noErr, "Can't expand highlight array" );
  386.         (**hh).array_size = ( GetHandleSize( (Handle)hh ) -
  387.                                     sizeof(high_info) ) / sizeof(Rect);
  388.     }
  389.     if ( (**hh).high_waiting < (**hh).array_size )
  390.     {
  391.         (**hh).high_rect[ (**hh).high_waiting ] = *rect;
  392.         (**hh).high_waiting++;
  393.     }
  394. }
  395.  
  396. /* --------------------------- Pop_highlight -------------------------- */
  397. static Boolean Pop_highlight( high_info **hh, Rect *rect )
  398. {
  399.     if ( (**hh).high_waiting > 0 )
  400.     {
  401.         (**hh).high_waiting--;
  402.         *rect = (**hh).high_rect[ (**hh).high_waiting ];
  403.         return true;
  404.     }
  405.     else
  406.         return false;
  407. }
  408.  
  409. /* ---------------------- Do_deferred_hilites ---------------------- */
  410. static void Do_deferred_hilites( help_ptr  hptr, Rect *update_rect )
  411. {
  412.     Rect    hilite;
  413.     
  414.     while (Pop_highlight( hptr->high, &hilite ))
  415.     {
  416.         if (SectRect( &hilite, update_rect, &hilite ))
  417.         {
  418.             HiliteMode &= ~(1 << hiliteBit);
  419.             InvertRect( &hilite );
  420.         }
  421.     }
  422.     hptr->high_defer_flag = false;
  423. }
  424. #endif USE_PICTS
  425.  
  426. /* --------------------------- Find_char -------------------------- */
  427. /*
  428.     Find a character within a handle.  In a previous version I did this
  429.     with Munger().
  430.     
  431.     returns: the offset of the character, or -1 if not found.
  432. */
  433. static short    Find_char(
  434.             Handle    data_h,        // handle to a block of characters
  435.             short    offset,        // initial offset within block
  436.             char    what )        // the character we're looking for
  437. {
  438.     Ptr        text;
  439.     short    text_size, scan;
  440.     
  441.     text_size = (short) GetHandleSize( data_h );
  442.     text = *data_h;
  443.     for (scan = offset; (text[scan] != what) && (scan < text_size); ++scan)
  444.         ;
  445.     if (scan == text_size) // not found
  446.         scan = -1;
  447.     return scan;
  448. }
  449.  
  450. /* --------------------------- Build_popup ------------------------- */
  451. /*
  452.     Build a popup menu of the sections of the help text.  We scan for
  453.     tab characters.  The text between the tab character and the preceding
  454.     line break will be a menu item, unless it is the null string; then we
  455.     use the default menu name that was passed to Show_help.
  456. */
  457. static MenuHandle Build_popup( TEHandle    the_text, StringPtr default_menuname )
  458. {
  459.     MenuHandle    popup;
  460.     short        menu_id;
  461.     SignedByte    text_state;
  462.     Handle        text_h;    /* handle to just the text */
  463.     Str255        menu_data;
  464.     char        *text;    /* pointer to the help text */
  465.     register short        scan, line_start;
  466.     short        text_size, title_length;
  467.     
  468.     /* Find an unused menu ID */
  469.     menu_id = 1300; /* no particular reason */
  470.     while (GetMHandle(menu_id))
  471.         ++menu_id;
  472.     
  473.     popup = NewMenu( menu_id, "\p" );
  474.     ASSERT( popup != NIL, "NewMenu failed" );
  475.  
  476.     text_h = (**the_text).hText;
  477.     text_state = HGetState( text_h );
  478.     HLock( text_h );
  479.     text = *text_h;
  480.     text_size = (short) GetHandleSize( text_h );
  481.     line_start = 0;
  482.     for (scan = 0; scan < text_size; scan++ )
  483.     {
  484.         if (text[scan] == '\r')
  485.         {
  486.             line_start = scan + 1;
  487.         }
  488.         else if (text[scan] == '\t')
  489.         {
  490.             title_length = scan - line_start;
  491.             if (title_length == 0)
  492.                 BlockMove( default_menuname, menu_data, 256 );
  493.             else
  494.             {
  495.                 menu_data[0] = title_length; // note: <= 255
  496.                 BlockMove( &text[line_start], &menu_data[1], menu_data[0] );
  497.             }
  498.             /*
  499.                 AppendMenu recognizes meta-characters like slash,
  500.                 which is probably not what we want in this case.  So
  501.                 we use SetItem, which does not use meta-characters.
  502.             */
  503.             AppendMenu( popup, "\p " );
  504.             SetItem( popup, CountMItems(popup), menu_data );
  505.         }
  506.     }
  507.     
  508.     HSetState( text_h, text_state );
  509.     return popup;
  510. }
  511.  
  512. /* ------------------------- Topic_menu ------------------------ */
  513. /*
  514.     This routine is called when the menu title is clicked.
  515.     It pops up the menu and scrolls to the indicated tab character.
  516. */
  517. static void Topic_menu( DialogPtr dptr, MenuHandle menu )
  518. {
  519.     short            menu_id;
  520.     Handle            item_h;
  521.     short            itype;
  522.     Rect            box;
  523.     Point            where;
  524.     long            menu_return;
  525.     short            menu_choice;
  526.     ControlHandle    bar;
  527.     register short        i;
  528.     register TEHandle    the_text;
  529.     Handle            text_h;
  530.     register short        offset;
  531.     TextStyle        what_style;
  532.     short            line_height, font_ascent;
  533.     
  534.     if (menu == NIL) return;
  535.     InsertMenu( menu, -1 );
  536.     GetDItem( dptr, c_menu, &itype, &item_h, &box );
  537.     where.h = box.left;
  538.     where.v = box.bottom;
  539.     LocalToGlobal( &where );
  540.     HiliteMode &= ~(1 << hiliteBit);
  541.     InvertRect( &box );
  542.     menu_return = PopUpMenuSelect( menu, where.v, where.h, 0 );
  543.     HiliteMode &= ~(1 << hiliteBit);
  544.     InvertRect( &box );
  545.     if (HiWord(menu_return))    /* Something selected */
  546.     {
  547.         menu_choice = LoWord( menu_return );
  548.         bar = ((help_ptr)dptr)->scrollbar;
  549.         the_text = (TEHandle) GetWRefCon( dptr );
  550.         text_h = (**the_text).hText;
  551.         
  552.         /* Find tab character number menu_choice */
  553.         offset = -1L;
  554.         for (i = 1; i <= menu_choice; ++i)
  555.         {
  556.             ++offset; /* so we don't find the same thing twice */
  557.             offset = Find_char( text_h, offset, '\t' );
  558.         }
  559.  
  560.         where = TEGetPoint( (short)offset, the_text );
  561.         TEGetStyle( (short)offset, &what_style, &line_height,
  562.             &font_ascent, the_text );
  563.         where.v -= line_height;    /* align to TOP of tab */
  564.         /*
  565.             Now where.v is in local coordinates.
  566.         */
  567.         where.v -= (**the_text).destRect.top;
  568.         SetCtlValue( bar,  where.v );
  569.         
  570.         Adjust_text( dptr );
  571.     }
  572.     menu_id = (**menu).menuID;
  573.     DeleteMenu( menu_id );
  574. }
  575.  
  576. /* ------------------------- Save_text ------------------------ */
  577. /*
  578.     This is called when the user clicks on the "Save as TeachText"
  579.     button.
  580. */
  581. static void Save_text( TEHandle the_text, StringPtr default_filename )
  582. {
  583.     Point        where;
  584.     SFReply        reply;
  585.     OSErr        err;
  586.     short        data_refnum, res_refnum, old_resfile;
  587.     Handle        text_data;
  588.     SignedByte    state;
  589.     long        count;
  590.     GrafPtr        save_port;
  591.     short        save_vol;
  592. #if USE_PICTS
  593.     register short        num_picts, pict_index;
  594.     Handle        old_pict, new_pict;
  595.     help_ptr    dptr;
  596. #endif
  597.     
  598.     GetPort( &save_port );
  599.     where.h = where.v = 100;
  600.     SFPutFile( where, "\pName of TeachText file:",
  601.         default_filename, NIL, &reply );
  602.     SetPort( save_port );
  603.  
  604.     if (reply.good)
  605.     {
  606.         old_resfile = CurResFile();
  607. #if USE_PICTS
  608.         dptr = (help_ptr) (**the_text).inPort;
  609.         num_picts = dptr->pict_count;
  610. #endif
  611.  
  612.         /*
  613.             The reason I use Create before FSDelete is that FSDelete
  614.             uses the PMSP and Create doesn't.  See TN 101.
  615.             
  616.             One reason that I use the old File Manager calls instead of
  617.             the newer "H" calls is that they involve more glue code
  618.             which adds to the size of the code resource.
  619.         */
  620.         err = Create( reply.fName, reply.vRefNum, 'ttxt', 'ttro' );
  621.         if (err == dupFNErr)
  622.         {
  623.             (void) FSDelete( reply.fName, reply.vRefNum );
  624.             err = Create( reply.fName, reply.vRefNum, 'ttxt', 'ttro' );
  625.         }
  626.         ASSERT( err == noErr, "\p error in Create" );
  627.         
  628.         (void) FSOpen( reply.fName, reply.vRefNum, &data_refnum );
  629.         
  630.         text_data = (**the_text).hText;
  631.         state = HGetState( text_data );
  632.         ASSERT( MemError() == noErr, "HGetState text_data error" );
  633.         HLock( text_data );
  634.         
  635.         count = GetHandleSize( text_data );
  636.         ASSERT( MemError() == noErr, "GetHandleSize text_data error" );
  637.         err = FSWrite( data_refnum, &count, *text_data );
  638.         ASSERT( err == noErr, "FSWrite error" );
  639.         err = FSClose( data_refnum );
  640.         ASSERT( err == noErr, "FSClose error" );
  641.         HSetState( text_data, state );
  642.  
  643. #if USE_PICTS
  644.         if (num_picts > 0)
  645.         {
  646.             (void) GetVol( NIL, &save_vol );
  647.             (void) SetVol( NIL, reply.vRefNum );
  648.             CreateResFile( reply.fName );
  649.             ASSERT( ResError() == noErr, "\pCreateResFile error" );
  650.             res_refnum = OpenResFile( reply.fName );
  651.             ASSERT( ResError() == noErr, "\pOpenResFile error" );
  652.             (void) SetVol( NIL, save_vol );
  653.             
  654.             for (pict_index = 0;
  655.                 pict_index < num_picts; ++pict_index )
  656.             {
  657.                 UseResFile( old_resfile );
  658.                 old_pict = (Handle) dptr->pict_data[pict_index].pict;
  659.                 if (old_pict == NIL)
  660.                     break;
  661.                 new_pict = old_pict;
  662.                 err == HandToHand( &new_pict );
  663.                 ASSERT( err == noErr, "HandToHand error" );
  664.                 UseResFile( res_refnum );
  665.                 AddResource( new_pict, 'PICT',
  666.                     pict_index + 1000, "\p" );
  667.                 ASSERT( ResError() == noErr, "AddResource error" );
  668.             }
  669.             CloseResFile( res_refnum );
  670.             (void) FlushVol( NIL, reply.vRefNum );
  671.             UseResFile( old_resfile );
  672.         }
  673. #endif
  674.     }
  675. }
  676.  
  677.  
  678. /* ------------------------- Auto_scroll ----------------------------- */
  679. /*
  680.     This is a ClikLoop routine, called repeatedly by TEClick when the
  681.     mouse is down.
  682. */
  683. static pascal Auto_scroll()
  684. {
  685.     register    WindowPtr    the_display;
  686.     register    ControlHandle    the_bar;
  687.     Point                    mouse_point;
  688.     Rect                    view_rect;
  689.     register     TEHandle    the_text;
  690.     
  691.     asm {
  692.         movem.l        a1-a5/d1-d7, -(SP)
  693.     }
  694.     CKPT( "Auto_scroll");
  695.     the_display = FrontWindow();
  696.     if ( (the_display != NIL) &&
  697.         (GetPtrSize((Ptr)the_display) == sizeof(help_record)) )
  698.     {
  699.         the_text = (TEHandle) GetWRefCon( the_display );
  700.         the_bar = ((help_ptr) the_display)->scrollbar;
  701.         
  702.         GetMouse( &mouse_point );
  703.         view_rect = (**the_text).viewRect;
  704.         if (mouse_point.v < view_rect.top)
  705.             Scroll_text( the_bar, inUpButton );
  706.         else if (mouse_point.v > view_rect.bottom)
  707.             Scroll_text( the_bar, inDownButton );
  708.     }
  709.     asm {
  710.         movem.L        (SP)+, a1-a5/d1-d7
  711.         moveQ        #1, D0
  712.     }
  713. }
  714.  
  715. #if USE_PICTS
  716. /* ------------------------- Draw_picts --------------------------------- */
  717. /*
  718.     Called by Adjust_text and Text_userItem_proc to draw pictures.
  719. */
  720. static void Draw_picts( WindowPtr the_window, Rect *update_rect )
  721. {
  722.     register TEHandle    the_text;
  723.     register short        pict_count, pict_index;
  724.     PicHandle    the_pict;
  725.     short         v_offset;
  726.     Rect        pict_loc, dummy;
  727.     
  728.     CKPT( "Draw_picts");
  729.     the_text = (TEHandle) GetWRefCon( the_window );
  730.     v_offset = (**the_text).destRect.top - (**the_text).viewRect.top
  731.         - TEXT_INSET;
  732.     pict_count = ((help_ptr) the_window)->pict_count;
  733.     for (pict_index = 0; pict_index < pict_count; pict_index++)
  734.     {
  735.         pict_loc = ((help_ptr) the_window)->pict_data[pict_index].bounds;
  736.         OffsetRect( &pict_loc, 0, v_offset );
  737.         if (!SectRect( &pict_loc, update_rect, &dummy ))
  738.             continue;
  739.         the_pict = ((help_ptr) the_window)->pict_data[pict_index].pict;
  740.         GetClip( ((help_ptr) the_window)->save_clip );
  741.         ClipRect( update_rect );
  742.         DrawPicture( the_pict, &pict_loc );
  743.         SetClip( ((help_ptr) the_window)->save_clip );
  744.     }
  745. }
  746.  
  747. #define        OPTION_SPACE_CHAR    0xCA
  748.  
  749. /* ---------------------- Find_pictures ---------------------------- */
  750. static void Find_pictures( DialogPtr dlog, short first_pict_id )
  751. {
  752.     register TEHandle    the_text;
  753.     Handle        text_h;
  754.     SignedByte    text_state;
  755.     register short        offset;
  756.     short        num_picts;
  757.     register short        which_pict;
  758.     pict_info    *pict;
  759.     Point        place;
  760.     short        line_height, font_ascent;
  761.     TextStyle    what_style;
  762.     
  763.     CKPT( "Find_pictures");
  764.     the_text = (TEHandle) GetWRefCon( dlog );
  765.     text_h = (**the_text).hText;
  766.     text_state = HGetState( text_h );
  767.     HLock( text_h );
  768.     
  769.     /* Count option-space characters in the text. */
  770.     offset = 0;
  771.     num_picts = 0;
  772.     offset = Find_char( text_h, offset, OPTION_SPACE_CHAR );
  773.     while ( offset >= 0 )
  774.     {
  775.         num_picts++;
  776.         offset++;
  777.         offset = Find_char( text_h, offset, OPTION_SPACE_CHAR );
  778.     }
  779.     
  780.     /* Allocate storage for an array of picture bounds. */
  781.     pict = (pict_info *) NewPtr( sizeof(pict_info) * num_picts );
  782.     ASSERT( pict != NIL, "NewPtr failed for pict_data" );
  783.     ((help_ptr)dlog)->pict_data = pict;
  784.     
  785.     /*
  786.         Initialize the picture info.  For each picture we record the
  787.         picture handle and its rectangle, in unscrolled window
  788.         coordinates.
  789.     */
  790.     offset = 0;
  791.     for (which_pict = 0; which_pict < num_picts; which_pict++)
  792.     {
  793.         pict[which_pict].pict = (PicHandle) Get_compressed_resource( 'PICT',
  794.             first_pict_id + which_pict );
  795.         if ( pict[which_pict].pict == NIL )
  796.             break;
  797.         offset = Find_char( text_h, offset, OPTION_SPACE_CHAR );
  798.         place = TEGetPoint( offset, the_text );
  799.         TEGetStyle( offset, &what_style, &line_height,
  800.             &font_ascent, the_text );
  801.         place.v -= line_height;    /* align picture with TOP of option-space */
  802.         offset++;
  803.         pict[which_pict].bounds = (**pict[which_pict].pict).picFrame;
  804.         OffsetRect( &pict[which_pict].bounds,
  805.             ( ((**the_text).destRect.right + (**the_text).destRect.left) -
  806.             (pict[which_pict].bounds.right + pict[which_pict].bounds.left)
  807.             ) / 2,
  808.             - pict[which_pict].bounds.top + place.v );
  809.     }
  810.     ((help_ptr)dlog)->pict_count = which_pict;
  811.     
  812. getout:
  813.     HSetState( text_h, text_state );
  814. }
  815. #endif /* USE_PICTS */
  816.  
  817. /* ---------------------- Scroll_text ---------------------------- */
  818. /*
  819.     This is used as a TrackControl actionProc for scrolling, and also
  820.     called by Auto_scroll for automatic scrolling.
  821. */
  822. static pascal void Scroll_text( ControlHandle the_bar, short part_code )
  823. {
  824.     register TEHandle    the_text;
  825.     register short        delta;
  826.     register WindowPtr    the_display;
  827.     short                old_value;
  828.     short                offset, line;
  829.     Point                place;
  830.     Rect                view;
  831.     TextStyle            style;
  832.     short                line_height, font_ascent;
  833.     
  834.     CKPT( "Scroll_text");
  835.     if (part_code != 0)
  836.     {
  837.         the_display = (**the_bar).contrlOwner;
  838.         the_text = (TEHandle) GetWRefCon( the_display );
  839.         view = (**the_text).viewRect;
  840.         place.h = view.left + TEXT_INSET;
  841.         
  842.         switch (part_code)
  843.         {
  844.             case inUpButton:
  845.                 place.v = view.top;
  846.                 /*
  847.                     If we get the offset of the left edge of the top line,
  848.                     then subtract 1, we should have an offset belonging
  849.                     to the previous line.
  850.                 */
  851.                 offset = TEGetOffset( place, the_text ) - 1;
  852.                 if (offset == -1) offset = 0;
  853.                 place = TEGetPoint( offset, the_text );
  854.                 TEGetStyle( offset, &style, &line_height, &font_ascent,
  855.                     the_text );
  856.                 delta = place.v - line_height - view.top;
  857.                 break;
  858.             case inDownButton:
  859.                 place.v = view.bottom + 2;
  860.                 offset = TEGetOffset( place, the_text );
  861.                 place = TEGetPoint( offset, the_text );
  862.                 /* Now place.v is at the baseline of the border line. */
  863.                 delta = place.v - view.bottom;
  864.                 break;
  865.             case inPageUp:
  866.                 /*
  867.                     I want top border line to remain visible, and
  868.                     the top of a line should end up at view.top.
  869.                 */
  870.                 place.v = view.top + 2;
  871.                 offset = TEGetOffset( place, the_text );
  872.                 place = TEGetPoint( offset, the_text );
  873.                 /* place.v is at the baseline of the top border line. */
  874.                 TEGetStyle( offset, &style, &line_height, &font_ascent,
  875.                     the_text );
  876.                 place.v += line_height - font_ascent;
  877.                 place.v -= view.bottom - view.top;
  878.                 offset = TEGetOffset( place, the_text );
  879.                 place = TEGetPoint( offset, the_text );
  880.                 TEGetStyle( offset, &style, &line_height, &font_ascent,
  881.                     the_text );
  882.                 delta = place.v - view.top;
  883.                 if (offset == 0)
  884.                     delta -= line_height;
  885.                 break;
  886.             case inPageDown:
  887.                 /*
  888.                     I want bottom border line to remain visible, and
  889.                     the bottom of a line should end up at view.bottom.
  890.                 */
  891.                 place.v = view.bottom - 2;
  892.                 offset = TEGetOffset( place, the_text );
  893.                 place = TEGetPoint( offset, the_text );
  894.                 /* place.v is at the baseline of the bottom border line. */
  895.                 TEGetStyle( offset, &style, &line_height, &font_ascent,
  896.                     the_text );
  897.                 place.v -= font_ascent; /* Top edge of bottom border line */
  898.                 place.v += view.bottom - view.top;
  899.                 /* We're looking at the bottom border of the next page. */
  900.                 offset = TEGetOffset( place, the_text );
  901.                 place = TEGetPoint( offset, the_text );
  902.                 TEGetStyle( offset, &style, &line_height, &font_ascent,
  903.                     the_text );
  904.                 delta =  place.v - line_height - view.bottom;
  905.                 if (offset == (**the_text).teLength)
  906.                     delta += line_height;
  907.                 break;
  908.         }
  909.         old_value = GetCtlValue( the_bar );
  910.         if ( ((delta < 0) && (old_value > 0)) ||
  911.             ((delta > 0) && (old_value < GetCtlMax(the_bar))) )
  912.         {
  913.             /*
  914.                 When this routine is called, TextEdit may have set the
  915.                 clipping region to the view rectangle, so we reset it
  916.                 here to make sure the scroll bar gets drawn.
  917.             */
  918.             GetClip( ((help_ptr) the_display)->save_clip );
  919.             ClipRect( &the_display->portRect );
  920.             SetCtlValue( the_bar, old_value + delta );
  921.             SetClip( ((help_ptr) the_display)->save_clip );
  922.         }
  923.         Adjust_text( the_display );
  924.     }
  925. }
  926.  
  927. /* ---------------------- Adjust_text ---------------------------- */
  928. /*
  929.     Called by Handle_scroll and Scroll_text to scroll the text and
  930.     pictures into sync with the scroll bar's control value.
  931. */
  932. static void Adjust_text( DialogPtr    dialog )
  933. {
  934.     register    TEHandle    the_text;
  935.     register    short    scroll_down;
  936.     short            old_scroll;
  937.     Rect            update_rect;
  938.     
  939.     CKPT( "Adjust_text");
  940.     the_text = (TEHandle) GetWRefCon( dialog );
  941.     old_scroll = (**the_text).viewRect.top - (**the_text).destRect.top;
  942.     scroll_down = old_scroll -
  943.         GetCtlValue( ((help_ptr) dialog)->scrollbar );
  944.     if (scroll_down == 0)
  945.         return;
  946. #if USE_PICTS
  947.     ((help_ptr) dialog)->high_defer_flag = true;
  948.     //((help_ptr) dialog)->high_waiting = 0;
  949. #endif
  950.     TEScroll( 0, scroll_down, the_text );
  951. #if USE_PICTS
  952.     update_rect = (**the_text).viewRect;
  953.     if (scroll_down > 0)
  954.     {
  955.         if (scroll_down < (update_rect.bottom - update_rect.top))
  956.             update_rect.bottom = update_rect.top + scroll_down;
  957.     }
  958.     else
  959.         if (- scroll_down < (update_rect.bottom - update_rect.top))
  960.             update_rect.top = update_rect.bottom + scroll_down;
  961.     Draw_picts( dialog, &update_rect );
  962.     Do_deferred_hilites( (help_ptr) dialog, &update_rect );
  963. #endif
  964. }
  965.  
  966.  
  967. /* ---------------------- Handle_scroll ---------------------------- */
  968. /*
  969.     Called by Help_filter to handle mouseDown events in the scroll bar.
  970. */
  971. static void Handle_scroll( DialogPtr dialog, short the_part, Point where )
  972. {
  973.     register    ControlHandle the_bar;
  974.     
  975.     CKPT( "Handle_scroll"); SetPort( dialog );
  976.     the_bar = ((help_ptr) dialog)->scrollbar;
  977.     if (the_part == inThumb)
  978.     {
  979.         (void) TrackControl( the_bar, where, NIL );
  980.         Adjust_text( dialog );
  981.     }
  982.     else
  983.         (void) TrackControl( the_bar, where, (ProcPtr)Scroll_text );
  984.     
  985. }
  986.  
  987. /* ---------------------- Help_filter ------------------------- */
  988. /*
  989.     This is the dialog event filter for our help window.
  990. */
  991. #define        RETURN_CHAR        0x0D
  992. #define        TILDE_CHAR        0x7E
  993. #define        ENTER_CHAR        0x03
  994. #define        ESCAPE_CHAR        0x1B
  995.  
  996. static pascal Boolean Help_filter( DialogPtr dialog,
  997.     EventRecord    *event, short *itemHit)
  998. {
  999.     Point    local_point;
  1000.     short    the_part;
  1001.     ControlHandle    the_control;
  1002.     short    charcode;
  1003.     register TEHandle    the_text;
  1004.     Rect    item_box;
  1005.     short    cursor;
  1006.     WindowPtr    which_window;
  1007.     Boolean    retval;
  1008.     RgnHandle    gray_rgn;
  1009.     Rect        gray_rect;
  1010.     
  1011.     retval = false; // usually, let the Dialog Mgr do further processing
  1012.     the_text = (TEHandle) GetWRefCon( dialog );
  1013.  
  1014.     GetMouse( &local_point );
  1015.     if (PtInRect( local_point, &(**the_text).viewRect ))
  1016.         SetCursor( *(((help_ptr) dialog)->ibeam_cursor) );
  1017.     else
  1018.         InitCursor();
  1019.     TEIdle( the_text );
  1020.     
  1021.     switch (event->what) {
  1022.         case nullEvent:
  1023.             break;
  1024.         case updateEvt:
  1025.             which_window = (WindowPtr) event->message;
  1026.             if ( (which_window != dialog) &&
  1027.                 (((help_ptr)dialog)->Handle_update != NIL) )
  1028.             {
  1029.                 (((help_ptr)dialog)->Handle_update)( which_window );
  1030.                 retval = true;    // done with this event
  1031.             }
  1032.             break;
  1033.         case mouseDown:
  1034.             CKPT( "Help_filter mousedown");
  1035.             the_part = FindWindow( event->where, &which_window );
  1036.             if (the_part == inMenuBar)
  1037.             {
  1038.                 /*
  1039.                     Calling MenuSelect lets one use the help and
  1040.                     application menus.
  1041.                 */
  1042.                 (void) MenuSelect( event->where );
  1043.                 retval = true;    // get rid of the beep
  1044.             }
  1045.             else if ( (which_window == dialog) && (the_part == inContent) )
  1046.             {
  1047.                 local_point = event->where;
  1048.                 GlobalToLocal( &local_point );
  1049.                 the_part = FindControl( local_point, dialog, &the_control );
  1050.                 if (the_part && ((**the_control).contrlMax > 1) )
  1051.                 {
  1052.                     Handle_scroll( dialog, the_part, local_point );    
  1053.                     *itemHit = 2;
  1054.                     retval = true;
  1055.                     break;
  1056.                 }
  1057.                 else if (PtInRect( local_point, &(**the_text).viewRect ))
  1058.                 {
  1059.                     if (event->modifiers & shiftKey)
  1060.                         TEClick( local_point, true, the_text );
  1061.                     else
  1062.                         TEClick( local_point, false, the_text );
  1063.                     retval = true;
  1064.                 }
  1065.             }
  1066.             else if ( (which_window == dialog) && (the_part == inDrag) )
  1067.             {
  1068.                 gray_rgn = GetGrayRgn();
  1069.                 gray_rect = (**gray_rgn).rgnBBox;
  1070.                 DragWindow( dialog, event->where, &gray_rect );
  1071.                 retval = true;    // no beep
  1072.             }
  1073.             break;
  1074.         case keyDown :    
  1075.         case autoKey :
  1076.             charcode = event->message & charCodeMask;
  1077.             /*
  1078.                 There's no Cancel button, so we treat the OK button
  1079.                 the same as a Cancel button.
  1080.             */
  1081.             if ( (charcode == RETURN_CHAR) || (charcode == ENTER_CHAR) ||
  1082.                 (charcode == TILDE_CHAR) || (charcode == ESCAPE_CHAR) ||
  1083.                 ((charcode == '.') && (event->modifiers & cmdKey)) )
  1084.             {
  1085.                 *itemHit = c_OK;    /* OK */
  1086.                 Flash_button( dialog, *itemHit );
  1087.                 retval = TRUE;
  1088.             }
  1089.             else if ( (charcode == 'c') && (event->modifiers & cmdKey) )
  1090.             {
  1091.                 (void) ZeroScrap();
  1092.                 TECopy( the_text );
  1093.                 SystemEdit(3);
  1094.                 local_point = (**the_text).selPoint;
  1095.                 *(long *)&local_point = PinRect( &(**the_text).viewRect,
  1096.                     local_point );
  1097.                 cursor = TEGetOffset( local_point, the_text );
  1098.                 TESetSelect( (long)cursor, (long)cursor, the_text );
  1099.                 event->what = nullEvent;
  1100.                 retval = true;
  1101.             }
  1102.             break;
  1103.     } /* end switch */
  1104.     
  1105.     return retval;
  1106. }
  1107.  
  1108.  
  1109. /* ---------------------- Text_userItem_proc ------------------------- */
  1110. static pascal void  Text_userItem_proc( WindowPtr the_window, short item_num )
  1111. {
  1112.     Handle        item_h;
  1113.     Rect        item_box;
  1114.     short        item_type;
  1115.     TEHandle    the_text;
  1116.         
  1117.     CKPT( "Text_userItem_proc");
  1118.     the_text = (TEHandle) GetWRefCon( the_window );
  1119.     item_box = (**the_text).viewRect;
  1120. #if USE_PICTS
  1121.     ((help_ptr) the_window)->high_defer_flag = true;
  1122. #endif
  1123.     TEUpdate( &item_box, the_text );
  1124.     
  1125. #if USE_PICTS
  1126.     Draw_picts( the_window, &item_box );
  1127.     Do_deferred_hilites( (help_ptr) the_window, &item_box );
  1128. #endif
  1129.  
  1130.     /*
  1131.         Get the item's rectangle, and frame it.
  1132.     */
  1133.     GetDItem( the_window, item_num, &item_type, &item_h, &item_box );
  1134.     FrameRect( &item_box );
  1135. }
  1136.  
  1137. /* ---------------------- Menu_userItem_proc ------------------------- */
  1138. static pascal void  Menu_userItem_proc( WindowPtr the_window, short item_num )
  1139. {
  1140.     Handle        item_h;
  1141.     Rect        item_box;
  1142.     short        item_type;
  1143.     
  1144.     CKPT( "Menu_UserItem_proc");
  1145.     
  1146.     /*
  1147.         Get the item's rectangle, and frame it.
  1148.     */
  1149.     GetDItem( the_window, item_num, &item_type, &item_h, &item_box );
  1150.     InsetRect(&item_box, -1, -1);
  1151.     FrameRect( &item_box );
  1152.     
  1153.     /* Draw the drop-shadow */
  1154.     MoveTo( item_box.left + 2, item_box.bottom );
  1155.     LineTo( item_box.right, item_box.bottom );
  1156.     LineTo( item_box.right, item_box.top + 2 );
  1157. }
  1158.  
  1159. /* ---------------------- Flash_button ----------------------------- */
  1160. pascal void Flash_button( DialogPtr the_dialog, short item_number )
  1161. {
  1162.     ControlHandle    item_h;
  1163.     long    time;
  1164.     short    itype;
  1165.     Rect    box;
  1166.     
  1167.     GetDItem( the_dialog, item_number, &itype, (Handle *)&item_h, &box );
  1168.     HiliteControl( item_h, inButton );
  1169.     Delay( 9L, &time );
  1170.     HiliteControl( item_h, 0 );
  1171. }
  1172.  
  1173. #if COMPRESSION
  1174. /* ---------------------- Get_compressed_resource ----------------------- */
  1175. static Handle Get_compressed_resource( ResType the_type, short the_ID )
  1176. {
  1177.     register Handle        CNVT_h;
  1178.     ParmInfo        info;
  1179.     CNVT_routine    Converter;
  1180.     
  1181.     info.srcHandle = GetResource( '4CMP', the_ID );
  1182.     CNVT_h = GetNamedResource( 'CNVT', "\p4CMPUncompress 4CMP" );
  1183.     if ( (info.srcHandle == NIL) ||    /* maybe there's an uncompressed one */
  1184.         (CNVT_h == NIL) )
  1185.     {
  1186.         info.dstHandle = GetResource( the_type, the_ID );
  1187.     }
  1188.     else    /* found a compressed resource */
  1189.     {
  1190.         info.srcType = '4CMP';
  1191.  
  1192.         HLock(CNVT_h);
  1193.         Converter = (CNVT_routine) StripAddress( *CNVT_h );
  1194.         CKPT("\pAbout to call the CNVT");
  1195.         (void) Converter( NIL, &info );
  1196.         CKPT("\pAfter the CNVT");
  1197.         HUnlock(CNVT_h);
  1198.         
  1199.         ReleaseResource( info.srcHandle );
  1200.     }
  1201.     return    info.dstHandle;
  1202. }
  1203.  
  1204. #define        mem_resource    0x20
  1205.  
  1206. /* ------------------------- Release_compressed_resource ------------- */
  1207. /*
  1208.     If it's a resource handle, release it, otherwise dispose of it.
  1209. */
  1210. static void Release_compressed_resource( Handle rsrc_h )
  1211. {
  1212.     if ( HGetState( rsrc_h ) & mem_resource )
  1213.         ReleaseResource( rsrc_h );
  1214.     else
  1215.         DisposHandle( rsrc_h );
  1216. }
  1217.  
  1218. /*    -------------------------------------------------------------------
  1219.     Dispose_compressed_data        If the handle is not a resource, hence
  1220.                                 the result of decompression, then
  1221.                                 dispose of it.  Otherwise (the case of
  1222.                                 an actual resource handle) do nothing.
  1223.     This is the what I do with PICTs, because a PICT may be doing double
  1224.     duty, say as a dialog item, and then it should not be released.
  1225.     -------------------------------------------------------------------
  1226. */
  1227. static void Dispose_compressed_data( Handle the_handle )
  1228. {
  1229.     if ( !(HGetState( the_handle ) & mem_resource) )
  1230.         DisposHandle( the_handle );
  1231. }
  1232. #endif COMPRESSION